<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            margin: 0 auto;
            width: 800px;
            height: 400px;
            position: relative;
            box-sizing: border-box;
        }

        .box-top{
            width: 800px;
            height: 400px;
            position: relative;
            display: flex;
            box-sizing: border-box;
        }
        .box1,
        .box2 {
            width: 400px;
            height: 400px;
            border: 1px solid black;
            overflow: hidden;
            box-sizing: border-box;
        }

        .box1 img {
            width: 400px;
            height: 400px;
        }

        .mask {
            width: 200px;
            height: 200px;
            background-color: rgba(169, 169, 169, 0.8);
            position: absolute;
        }

        .box2 img {
            height: 200%;
            width: 200%;
        }

        .box-bottom {
            width: 400px;
            height: 100px;
            display: flex;
            box-sizing: border-box;
        }
        .box-bottom img:hover{
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box-top">
            <div class="box1">
                <div class="mask"></div>
                <img src="./Mate 50 Pro曜金黑.jpg" alt="" class="xiaotu">
            </div>
            <div class="box2">
                <img src="./Mate 50 Pro曜金黑.jpg" alt="" class="datu">
            </div>
        </div>
        <div class="box-bottom">
            <img src="./Mate 50 Pro曜金黑.jpg" alt="">
            <img src="./Mate 50 Pro 冰霜银.jpg" alt="">
            <img src="./Mate 50 Pro昆仑破晓.jpg" alt="">
            <img src="./Mate 50 Pro昆仑霞光.jpg" alt="">
        </div>
    </div>

    <script>
        let mask = document.querySelector(".mask")
        let box = document.querySelector(".box")
        let box1 = document.querySelector(".box1")
        let box2 = document.querySelector(".box2")
        let img = document.querySelector(".box2>img")
        let box_bottom = document.querySelector(".box-bottom")
        let xiaotu = document.querySelector(".xiaotu")
        let datu = document.querySelector(".datu")

        
        box_bottom.addEventListener("mousemove",function(e){
            datu.src = e.target.src
            xiaotu.src = e.target.src
        })
        

        box1.addEventListener("mousemove", function (event) {
            //pageX、clientX
            box2.style.display = `block`
            let moveX = event.pageX - box.offsetLeft - mask.offsetWidth / 2
            let moveY = event.pageY - box.offsetTop - mask.offsetHeight / 2
            if (moveX <= 0) {
                moveX = 0
            }
            if (moveX >= box1.offsetWidth - mask.offsetWidth) {
                moveX = box1.offsetWidth - mask.offsetWidth
            }
            if (moveY <= 0) {
                moveY = 0
            }
            if (moveY >= box1.offsetHeight - mask.offsetHeight) {
                moveY = box1.offsetHeight - mask.offsetHeight
            }
            mask.style = `transform:translate(${moveX}px,${moveY}px)`
            img.style = `transform:translate(${-moveX * 2}px,${-moveY * 2}px)`
        })
        box1.addEventListener("mouseleave",function(){
            mask.style.display = `none`
            box2.style.display = `none`
        })
    </script>
</body>

</html>